package com.asktgapp.dialog;


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.asktgapp.JGTool.JGColor;
import com.asktgapp.R;
import com.asktgapp.model.BalanceVO;
import com.asktgapp.model.BankVO;
import com.wx.wheelview.adapter.ArrayWheelAdapter;
import com.wx.wheelview.widget.WheelView;

import java.util.ArrayList;
import java.util.List;


/**
 * Description:{}
 * time:2017/8/14
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 */

@SuppressLint("ValidFragment")
public class ChooseBankFragment extends DialogFragment implements View.OnClickListener {
    public static final String TAG = ChooseBankFragment.class.getSimpleName();
    private TextView mSureTV, mCancel;//确定
    private Callback callback;
    private List<String> mDatas;
    private List<String> mList = new ArrayList<>();
    private WheelView mWheelView;
    private String mTitle;

    /**
     * @param callback 回调的内部类，用来供给调用线程做返回处理
     * @param mDatas   调用时传入的提示信息
     */
    @SuppressLint("ValidFragment")
    public ChooseBankFragment(Callback callback, List<BankVO> mDatas, String title) {
        this.callback = callback;
        for (BankVO bean : mDatas) {
            this.mList.add(bean.getName());
        }
        this.mTitle = title;

    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(getContext());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //fragment的视图
        dialog.setContentView(R.layout.dialog_choose_type);
        mSureTV = (TextView) dialog.findViewById(R.id.sure_tv);
        mSureTV.setOnClickListener(this);
        mCancel = (TextView) dialog.findViewById(R.id.cancel_tv);
        mCancel.setOnClickListener(this);
        TextView title = (TextView) dialog.findViewById(R.id.title);
        title.setText(mTitle);
        mWheelView = (WheelView) dialog.findViewById(R.id.wheelview);
        WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
        mWheelView.setWheelAdapter(new ArrayWheelAdapter(getActivity()));
        mWheelView.setWheelData(mList);
        mWheelView.setSkin(WheelView.Skin.Holo);
        style.textSize = 18;
        style.textColor = JGColor.APP_TEXT_SECOND;
        //// TODO: 2018/2/9  
        style.selectedTextColor = JGColor.APP_BASIC_BLUE;
        style.selectedTextSize = 20;
        mWheelView.setStyle(style);
        //
        Window window = dialog.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        WindowManager.LayoutParams params = window.getAttributes();
        WindowManager windowManager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        window.setBackgroundDrawableResource(R.drawable.dialog_bg);
        Display display = windowManager.getDefaultDisplay();
        params.width = display.getWidth();
        params.gravity = Gravity.BOTTOM;
        params.windowAnimations = R.style.popwin_anim_style;
        window.setAttributes(params);
        return dialog;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sure_tv:
                String name = mList.get(mWheelView.getCurrentPosition());
                callback.onSelect(name);
                dismiss();
                break;
            case R.id.cancel_tv:
                dismiss();

        }
    }


    public interface Callback {
        public void onSelect(String... s);
    }


}
